// app.js
App({
  onLaunch() {
    //云开发初始化
    wx.cloud.init({
      env: 'gzwzqsr-cjy-1geik385af601016'
    }),

    //调用云函数
    wx.cloud.callFunction({
      name: 'get_openId',
      success: res => {
        //获取用户openid
        this.globalData.user_openid = res.result.openid
        // console.log(this.globalData.user_openid)

         //在数据库中查找用户是否已经登录过了
         wx.cloud.database().collection('user').where({
          _openid: res.result.openid
        }).get({
          success: result => {
            this.globalData.userInfo = result.data[0]
      }
    })
  }
})

  

    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
  },
  //全局数据
  globalData: {
    //用户openid
    user_openid: '',
    //用户信息
    userInfo: null
  }
})
